﻿@model XPressify.Models.NewsFeedModel
@using XPressify.Models
@using XPressify.Data.Helpers;

@{
    var index = 0;
    var specialUpdateId = "";
    var myFirstElementPost = "";
    foreach (var item in Model.AllPosts)
    {
            myFirstElementPost = "";
            if (index == 0)
            {
                myFirstElementPost = "myfirstElementPost";
            }
           <div id="@item.Key.Id" class="myfirstElementPostNew" style="display:none">
               <table border="0" cellpadding="0" cellspacing="0" style="margin:0px;padding:0px;width:553px">
                    <tr>
                        <th style="padding: 0px 2px 0px 2px;"> 
                            @Html.Raw(item.Key.Content)
                        </th>
                    @if (item.Key.BaseSubject.Id == Model.ViewerUserId || (item.Key.Creator != null && item.Key.Creator.Id == Model.ViewerUserId))
                    {
                        <td style="padding: 0px 2px 0px 2px;vertical-align:top;background-color: #E8EEF4;text-align:right">
                            @if (item.Key.PostType == PostType.PostNewsFeed)
                            {
                                @Html.Partial("BtnPostDelete", new BtnPostDeleteModel { PostId = item.Key.Parent.Id })
                            }
                            else
                            {
                                @Html.Partial("BtnPostDelete", new BtnPostDeleteModel { PostId = item.Key.Id })
                            }
                        </td>
                    }
                    </tr>
                </table>
                @foreach (var comment in item.Value)
                {   
                    <div id="@comment.Id">
                        <table border="0" cellpadding="0" cellspacing="0" style="margin:0px;padding:0px;width:553px">
                            <tr>
                                <th width="0px" style="padding: 0px 2px 0px 2px"> 
                                    @Html.Raw(comment.Content)
                                </th>
                            @if (comment.BaseSubject.Id == Model.ViewerUserId)
                            {
                                <th style="padding: 0px 2px 0px 2px;vertical-align: top;text-align:right"> 
                                    @Html.Partial("BtnPostCommentDelete", new BtnPostDeleteModel { PostId = comment.Id })
                                </th>
                            }
                            </tr>
                        </table>
                    </div>
                }

                @{specialUpdateId = item.Key.Id + "Update";}
                <div id="@specialUpdateId"></div>

                @if (item.Key.CommentType != CommentType.PostWithoutComments)
                {
                    var postId = item.Key.Id;
                    if (item.Key.PostType == PostType.PostNewsFeed)
                    {
                        postId = item.Key.Parent.Id;
                    }
                @Html.Partial("WriteComment", new PostCommentModel { PostId = postId, ContentText = "Write a comment...", ProfilePicturePath = Model.ViewerProfilePicturePath })
                }
    
                ______________________________________________________________________________
            </div>
        index++;
    }

}